/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JPnlSegments.java
 *
 * Created on 15/07/2010, 16:20:10
 */
package systole.view.tabs;

import java.awt.CardLayout;

import systole.domain.signals.Segment;
import systole.view.tabs.controllers.AnalysisController;
import systole.view.tabs.segments.JPnlAutoSelection;
import systole.view.tabs.segments.JPnlImageMap;
import systole.view.tabs.segments.JPnlImagesFlow;

/**
 * 
 * @author jmj
 */
public class JPnlSegments extends javax.swing.JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 407054349187801699L;
	private AnalysisController controller;
	private JPnlImagesFlow imagesFlow;
	private JPnlImageMap imageMap;
	private JPnlAutoSelection autoSelection;

	private String lastPanel = null;

	/**
	 * Creates new form JPnlSegments
	 * 
	 * @param controller
	 * */
	public JPnlSegments(AnalysisController controller) {
		initComponents();
		this.controller = controller;

		this.imageMap = new JPnlImageMap(this.controller, this);
		this.controller.getSelectionModel().addObserver(this.imageMap);
		this.imagesFlow = new JPnlImagesFlow(this.controller, this);
		this.controller.getSelectionModel().addObserver(this.imagesFlow);
		this.autoSelection = new JPnlAutoSelection(this.controller, this);
		this.controller.getSelectionModel().addObserver(this.autoSelection);
		this.add(this.autoSelection, "correlation");
		this.add(this.imagesFlow, "imageFlow");
		this.add(this.imageMap, "imageMap");
		this.showImageMap();
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
	// <editor-fold defaultstate="collapsed"
	// desc="Generated Code">//GEN-BEGIN:initComponents
	private void initComponents() {

		setName("Form"); // NOI18N
		setLayout(new java.awt.CardLayout());
	}// </editor-fold>//GEN-END:initComponents

	// Variables declaration - do not modify//GEN-BEGIN:variables
	// End of variables declaration//GEN-END:variables
	/**
	 * show image flow panel
	 */
	public void showImageFlow() {
		CardLayout cl = (CardLayout) this.getLayout();
		cl.show(this, "imageFlow");
		this.lastPanel = "imageFlow";
	}

	/**
	 * show image map panel
	 */
	public void showImageMap() {
		CardLayout cl = (CardLayout) this.getLayout();
		cl.show(this, "imageMap");
		this.lastPanel = "imageFlow";
	}

	/**
	 * show auto selection panel
	 */
	public void showAutoSelection() {
		CardLayout cl = (CardLayout) this.getLayout();
		cl.show(this, "correlation");
	}

	/**
	 * show last panel showed
	 */
	public void showLastPanel() {
		CardLayout cl = (CardLayout) this.getLayout();
		if (this.lastPanel != null) {
			cl.show(this, lastPanel);
		}
		cl.show(this, "imageMap");
	}

	/**
	 * @return the imagesFlow
	 */
	public JPnlImagesFlow getImagesFlow() {
		return imagesFlow;
	}

	/**
	 * @return the imageMap
	 */
	public JPnlImageMap getImageMap() {
		return imageMap;
	}

	/**
	 * @return the autoSelection
	 */
	public JPnlAutoSelection getAutoSelection() {
		return autoSelection;
	}
	
	
	/**
	 * @param segment
	 */
	public void applyCorrelation(Segment segment) {
		this.autoSelection.loadSegmentToCorrelation(segment);
		this.showAutoSelection();
	}
}
